# Contributor: Kay Thomas <kaythomas@pm.me>
# Maintainer: Kay Thomas <kaythomas@pm.me>
pkgname=thelounge
pkgver=4.3.1
pkgrel=1
pkgdesc="Modern, responsive, cross-platform, self-hosted web IRC client"
url="https://thelounge.chat"
# building node-sqlite3 requires python 2 on other arches
arch="x86_64"
license="MIT"
depends="nodejs"
makedepends="yarn npm libc6-compat python3"
subpackages="$pkgname-openrc"
pkgusers="thelounge"
pkggroups="thelounge"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/thelounge/thelounge/archive/v$pkgver.tar.gz
	skip-version-tests.patch
	thelounge.initd
	"

prepare() {
	default_prepare

	yarn install --legacy-peer-deps
	NODE_ENV=production yarn run build
}

package() {
	NODE_ENV=production npm install -g --prefix "$pkgdir"/usr

	# Remove incorrect symlink, copy correct files
	rm "$pkgdir"/usr/lib/node_modules/thelounge
	mkdir -p "$pkgdir"/usr/lib/node_modules/thelounge
	cp -a "$builddir"/* "$pkgdir"/usr/lib/node_modules/thelounge/

	# Set home location
	echo /etc/thelounge > \
		"$pkgdir"/usr/lib/node_modules/$pkgname/.thelounge_home

	# Add default config
	install -dm755 -o thelounge -g thelounge \
		"$pkgdir"/etc/thelounge
	install -m644 -o thelounge -g thelounge \
		"$pkgdir"/usr/lib/node_modules/$pkgname/defaults/config.js \
		"$pkgdir"/etc/thelounge/config.js

	install -Dm755 "$srcdir"/$pkgname.initd \
		"$pkgdir"/etc/init.d/$pkgname
}

check() {
	yarn run test:mocha
}

sha512sums="
0a5d8666f0d3def2be6b31ce9313acdbe8c1b6413b679a47886d6d2a255301d6d526018b801f9adbd2a87211708a2f696646598758a6726e47a01c632dae6122  thelounge-4.3.1.tar.gz
46ecadeed77625fcf94ab7b496e85c19bf1da3bcf17be21bd9440d8d5e22d428e6a94bc976ebabeaafb3363f09e7321fee29260ab866aca6b1538937dd84de58  skip-version-tests.patch
f367d27ebcc412ff03c12ae98e50aeae5051fb5ffa9da6220f664c59993ed0e330b55b3b41fe941d546634901163d006e318891b4b886f6c49a93e0888fccd3e  thelounge.initd
"
